package main

import (
	"fmt"
	"strconv"
)

// 演示golang string转基本数据类型
func main() {

	var strB string = "false"
	var b bool = true
	b, _ = strconv.ParseBool(strB)
	fmt.Printf("b type %T, b value %v\n", b, b)

	var strI string = "123"
	i, _ := strconv.ParseInt(strI, 10, 64)
	fmt.Printf("i type %T, I value %v\n", i, i)

	var strf string = "3.14"
	f, _ := strconv.ParseFloat(strf, 64)
	fmt.Printf("f type %T, f value %v\n", f, f)

	str := "中国"
	stri, _ := strconv.ParseInt(str, 10, 64)
	//转换失败 返回值 0
	fmt.Printf("stri type %T, stri value %v\n", stri, stri)

	//转失败 默认值
	b, _ = strconv.ParseBool(str)
	fmt.Printf("b type %T, b value %v\n", b, b)

}
